import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;


public abstract class Entity{
	public int posX, posY; //grid position
	public float actualX, actualY; //actual position
	public static String IMAGE;
	protected SpriteSheet sheet;
	private Image img;
	
	public Entity(String imagePath, int x, int y) {
		IMAGE = imagePath;
		loadImage();
		sheet = new SpriteSheet(img, 32, 32);
		posX = x;
		posY = y;
		updatePositionSnap();
	}
	
	//loads image to img field
	private boolean loadImage() {
		try {
			img = new Image(IMAGE);
			return true;
		} catch (SlickException e) {
			System.err.println("Can't load " + IMAGE);
			return false;
		}
	}
	
	public int getX() {return posX;}
	public int getY() {return posY;}
	
	public void update() {
		
		updatePositionSnap();
	}
	
	public void updatePositionSnap() {
		//needs to be updated
		actualX = posX * Map.TILE_SIZE;
		actualY = posY * Map.TILE_SIZE;
	}
	public void updatePositionSmooth() {
		int speed = Map.TILE_SIZE / 16;
		actualX += speed * Math.signum(posX * Map.TILE_SIZE - actualX);
		actualY += speed * Math.signum(posY * Map.TILE_SIZE - actualY);
	}
	
	public void render() {
		sheet.getSprite(0, 0).draw(actualX, actualY);
	}
}